home *** CD-ROM | disk | FTP | other *** search
- var G_GDEBUG_LOADER = false;
- var Cc = Components.classes;
- var Ci = Components.interfaces;
- var PROT_appContext = this;
- var PROT_application;
- var PROT_LIB_ROOT = "amulet-jslib";
- var PROT_LIBS = [
- "google3/lang.js",
- "google3/thread-queue.js",
- "google3/eventregistrar.js",
- "google3/listdictionary.js",
- "google3/arc4.js",
- "firefox/lang.js",
- "firefox/preferences.js",
- "firefox/alarm.js",
- "firefox/base64.js",
- "firefox/observer.js",
- "firefox/filesystem.js",
- "firefox/protocol4.js",
- "firefox/debug.js",
- "firefox/tabbedbrowserwatcher.js",
- "firefox/navwatcher.js",
- "firefox/cryptohasher.js",
- "firefox/objectsafemap.js",
- "firefox/version-utils.js",
- "url-canonicalizer.js",
- "enchash-decrypter.js",
- "trtable.js",
- "firefox-commands.js",
- "url-crypto-key-manager.js",
- "url-crypto.js",
- "xml-fetcher.js",
- "tr-fetcher.js",
- "reporter.js",
- "wireformat.js",
- "globalstore.js",
- "browser-view.js",
- "phishing-afterload-displayer.js",
- "list-warden.js",
- "phishing-warden.js",
- "listmanager.js",
- "controller.js",
- "application.js",
- "content-analyzer.js",
- "sandbox.js"
- ];
- var G_GDEBUG = false;
- function LOADER_dump(msg) {
- if (G_GDEBUG_LOADER) {
- for (var i = 1; i < arguments.length; i++) {
- msg = msg.replace(/\%s/, arguments[i]);
- }
- dump("[TB BOOTSTRAP LOADER] " + msg + "\n");
- }
- }
- var PROTTB_loader = new function() {
- var CONTRACT_ID_PREFIX = "@google.com/tbsafebrowsing/";
- var LOADER_CONTRACT_ID = "application;1";
- var components = [];
- var componentsLookup = {};
- this.init = function() {
- LOADER_dump("initializing...");
- loadLibs();
- LOADER_dump("registering loader service...");
- this.registerComponent(LOADER_CONTRACT_ID,
- "{888f29f2-b2ec-41e8-a965-12d3780fefca}",
- "PROTTB_loader",
- ["xpcom-startup"]);
- };
- this.registerComponent =
- function(contractId, classId, className, categories) {
- var component = { contractId: contractId,
- classId: classId,
- className: className,
- categories: categories };
- components.push(component);
- componentsLookup[component.classId] = component;
- };
- this.registerSelf = function(compMgr, fileSpec, location, type) {
- LOADER_dump("registering XPCOM components... ");
- compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
- for (var i = 0, component; component = components[i]; i++) {
- LOADER_dump(" registering {%s} as {%s}",
- component.className,
- component.contractId);
- compMgr.registerFactoryLocation(Components.ID(component.classId),
- component.className,
- CONTRACT_ID_PREFIX +
- component.contractId,
- fileSpec,
- location,
- type);
- if (component.categories && component.categories.length) {
- var catMgr = Cc["@mozilla.org/categorymanager;1"]
- .getService(Ci.nsICategoryManager);
- for (var j = 0, category; category = component.categories[j]; j++) {
- LOADER_dump(" registering category {%s}", category);
- catMgr.addCategoryEntry(category,
- component.className,
- CONTRACT_ID_PREFIX + component.contractId,
- true,
- true);
- }
- }
- }
- };
- this.getClassObject = function(compMgr, cid, iid) {
- LOADER_dump("getting factory for class {%s} and interface {%s}...",
- cid, iid);
- var comp = componentsLookup[cid.toString()];
- if (!comp)
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
- if (!iid.equals(Ci.nsIFactory))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return new PROT_Factory(comp);
- };
- this.canUnload = function(compMgr) {
- return true;
- };
- function loadLibs() {
- for (var i = 0, libPath; libPath = PROT_LIBS[i]; i++) {
- LOADER_dump("Loading library {%s}", libPath);
- Cc["@mozilla.org/moz/jssubscript-loader;1"]
- .getService(Ci.mozIJSSubScriptLoader)
- .loadSubScript(getLibUrl(libPath));
- }
- };
- function getLibUrl(path) {
- var file = __LOCATION__.clone().parent.parent;
- var parts = path.split("/");
- file.append(PROT_LIB_ROOT);
- for (var i = 0, part; part = parts[i]; i++)
- file.append(part);
- if (!file.exists())
- throw new Error("Specified library {" + file.path + "} does not exist");
- return Cc["@mozilla.org/network/protocol;1?name=file"]
- .getService(Ci.nsIFileProtocolHandler)
- .getURLSpecFromFile(file);
- };
- this.__defineGetter__("wrappedJSObject", function() { return this; });
- this.appContext = PROT_appContext;
- this.observe = function(subject, topic, data) {
- if (topic != "xpcom-startup")
- return;
- function onProfileAfterChange() {
- if (PROT_Application.isCompatibleWithThisFirefox()) {
- LOADER_dump("Starting application...");
- PROT_application = new PROT_Application();
- } else
- LOADER_dump("Not starting application (incompatible ffox)...");
- };
- new G_ObserverServiceObserver("profile-after-change",
- onProfileAfterChange,
- true /* unregister after observing */);
- };
- this.QueryInterface = function(iid) {
- var Ci = Components.interfaces;
- if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIObserver))
- return this;
- throw Components.results.NS_ERROR_NO_INTERFACE;
- };
- }
- function PROT_Factory(comp) {
- this.comp = comp;
- }
- PROT_Factory.global = this;
- PROT_Factory.prototype.createInstance = function(outer, iid) {
- LOADER_dump("Factory creating instance for iid {%s}", iid);
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- var scriptObj = PROT_Factory.global[this.comp.className];
- if (!scriptObj)
- throw new Error("Could not find global object with name {%s}",
- this.comp.className);
- var retVal = (typeof scriptObj == "function") ? new scriptObj() : scriptObj;
- if (retVal.QueryInterface) {
- retVal.QueryInterface(iid);
- }
- return retVal;
- }
- PROTTB_loader.init();
- LOADER_dump("initialization complete");
- function NSGetModule() {
- LOADER_dump("NSGetModule called");
- return PROTTB_loader;
- }
-